External force extension - #222
Open
LudwigBoess wants to merge 3 commits into
Open
Conversation
LudwigBoess
marked this pull request as ready for review
August 7, 2026 20:30
Collaborator
|
@LudwigBoess i think this is a bit too destructive and backwards incompatible. let's go with something like this: define a new trait in namespace traits::fieldsetter {
template <class T, Dimension D>
concept HasFx1WithIndex = requires(const T& t, const coord_t<D>& x_Ph, prtlidx_t p) { ... };
// note that we are NOT passing particle arrays here.
}change the concept ExtFieldPolicyClass = ... or ::traits::fieldsetter::HasFx1WithIndex<F, D> ...;then in the pusher you can have: static constexpr auto HasExtFx1 = ::traits::fieldsetter::HasFx1<F, D>;
static constexpr auto HasExtFx1WithIndex = ::traits::fieldsetter::HasFx1WithIndex<F, D>;
// ... then when calling in the `getExternalForce`:
if constexpr (HasExtFx1WithIndex) {
f_x1 = policies.external_fields_policy.fx1(x_Ph, p);
} else if constexpr (HasExtFx1) {
f_x1 = policies.external_fields_policy.fx1(x_Ph);
} ...Now in the problem generator, when you define the external fields class with the new caller: template <Dimension D>
class MyExtField {
ParticleArrays prtls;
MyExtField(const ParticleArrays& prtls) : prtls { prtls } {}
public:
Inline auto fx1(const coord_t<D>&, prtlidx_t p) const -> real_t { ... }
};
// then in pgen class:
auto ExternalFields(simtime_t time, spidx_t sp, const Domain<S, M>& domain) const -> std::pair<bool, MyExtFields<M::Dim> {
return { true, MyExtFields<M::Dim> { domain.species[sp - 1] } }; // this will cast Particles object to ParticleArrays which is serializable
}And that should be it. the old functionality will still work while allowing for additional flexibility. Do you wanna give it a shot, or should i do that? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added the option to access particle properties in the external force computation. This allows to compute more than just external force fields.